<template>
<div style="height:600px;overflow-y: auto; ">
  <!-- <div class="head_title">基本信息</div> -->
  <el-form ref="form" :model="form" :rules="rules" style="margin-top: 16px;" size="small" label-width="160px">
	<el-form-item label="企业名称"  prop="deptNum" style="display:inline-block;width:48%;">
         <el-input v-model="form.enterpriseName" style="width: 370px;"/>
    </el-form-item>
	<el-form-item label="统一社会信用代码"  prop="deptNum" style="display:inline-block;width:48%;">
         <el-input v-model="form.socialCreditCode" style="width: 370px;"/>
    </el-form-item>
	<el-form-item label="法定代表人"  prop="deptNum" style="display:inline-block;width:48%;">
         <el-input v-model="form.legalRepresent" style="width: 370px;"/>
    </el-form-item>
	<el-form-item label="注册号"  prop="deptNum" style="display:inline-block;width:48%;">
         <el-input v-model="form.registNum" style="width: 370px;"/>
    </el-form-item>
	<el-form-item label="注册资金(万元)"  prop="deptNum" style="display:inline-block;width:48%;">
         <el-input v-model="form.registFunds" style="width: 370px;"/>
    </el-form-item>
	<el-form-item label="注册币种"  prop="deptNum" style="display:inline-block;width:48%;">
         <el-input v-model="form.registCurrency" style="width: 370px;"/>
    </el-form-item>
    <el-form-item label="成立日期"  prop="deptNum" style="display:inline-block;width:48%;">
		 <el-form-item prop="date1">
					<el-date-picker  type="date"   v-model="form.foundDate" style="width: 370px;"></el-date-picker>
		</el-form-item>
    </el-form-item>
      <el-form-item label="营业时间自"  prop="deptNum" style="display:inline-block;width:48%;">
		 <el-form-item prop="date1">
					<el-date-picker  type="date"   v-model="form.businessValLower" style="width: 370px;"></el-date-picker>
		</el-form-item>
    </el-form-item>
    <el-form-item label="营业时间至"  prop="deptNum" style="display:inline-block;width:48%;">
		 <el-form-item prop="date1">
					<el-date-picker  type="date"   v-model="form.businessValUpper" style="width: 370px;"></el-date-picker>
		</el-form-item>
    </el-form-item>
	<el-form-item label="登记状态"  prop="deptNum" style="display:inline-block;width:48%;">
         <el-input v-model="form.registStatus" style="width: 370px;"/>
    </el-form-item>
    <el-form-item label="注销日期"  prop="deptNum" style="display:inline-block;width:48%;">
		 <el-form-item prop="date1">
					<el-date-picker  type="date"   v-model="form.logoutDate" style="width: 370px;"></el-date-picker>
		</el-form-item>
    </el-form-item>
    <el-form-item label="吊销日期"  prop="deptNum" style="display:inline-block;width:48%;">
		 <el-form-item prop="date1">
					<el-date-picker  type="date"   v-model="form.revokeDate" style="width: 370px;"></el-date-picker>
		</el-form-item>
    </el-form-item>
	<el-form-item label="住所"  prop="deptNum" style="display:inline-block;width:48%;">
         <el-input v-model="form.domicile" style="width: 370px;"/>
    </el-form-item>
	<el-form-item label="登记机关"  prop="deptNum" style="display:inline-block;width:48%;">
         <el-input v-model="form.registOrg" style="width: 370px;"/>
    </el-form-item>
	<el-form-item label="类型"  prop="deptNum" style="display:inline-block;width:48%;">
         <el-input v-model="form.type" style="width: 370px;"/>
    </el-form-item>
	<el-form-item label="最后年检年度"  prop="deptNum" style="display:inline-block;width:48%;">
         <el-input v-model="form.lastYearCheckYear" style="width: 370px;"/>
    </el-form-item>
     <el-form-item label="最后年检日期"  prop="deptNum" style="display:inline-block;width:48%;">
		 <el-form-item prop="date1">
					<el-date-picker  type="date"   v-model="form.lastYearCheckDate" style="width: 370px;"></el-date-picker>
		</el-form-item>
    </el-form-item>
	<el-form-item label="行业门类代码"  prop="deptNum" style="display:inline-block;width:48%;">
         <el-input v-model="form.industryCategoryCode" style="width: 370px;"/>
    </el-form-item>
	<el-form-item label="行业门类名称"  prop="deptNum" style="display:inline-block;width:48%;">
         <el-input v-model="form.industryCategoryName" style="width: 370px;"/>
    </el-form-item>
	<el-form-item label="国民经济行业代码"  prop="deptNum" style="display:inline-block;width:48%;">
         <el-input v-model="form.nationEconomyIndustryCode" style="width: 370px;"/>
    </el-form-item>
	<el-form-item label="国民经济行业名称"  prop="deptNum" style="display:inline-block;width:48%;">
         <el-input v-model="form.nationEconomyIndustryName" style="width: 370px;"/>
    </el-form-item>
	<el-form-item label="实收资本"  prop="deptNum" style="display:inline-block;width:48%;">
         <el-input v-model="form.paidCapital" style="width: 370px;"/>
    </el-form-item>
    <el-form-item label="原注册号"  prop="deptNum" style="display:inline-block;width:48%;">
         <el-input v-model="form.originRegistNum" style="width: 370px;"/>
    </el-form-item>
	 <el-form-item label="核准时间"  prop="deptNum" style="display:inline-block;width:48%;">
		 <el-form-item prop="date1">
					<el-date-picker  type="date"   v-model="form.approvalTime" style="width: 370px;"></el-date-picker>
		</el-form-item>
    </el-form-item>
    <!-- <el-form-item label="">
      <el-button :loading="loading" size="medium" type="primary" @click="doSubmit">保存配置</el-button>
    </el-form-item> -->
  </el-form>
  </div>
</template>

<script>
import { get, update } from '@/api/alipay'
import { general,list,credentials,addCredentials,effective,commerce} from '@/api/custComBaseinfo'
import initData from '@/mixins/initData'
import { parseTime } from '@/utils/index'
import checkPermission from '@/utils/permission'
export default {
  name: 'Config',
  mixins: [initData],
  data() {
    return {
	  dialog:false,
	  loading: false,
	  addLoading:false,
	  id:'',
      form: { 
		   enterpriseName:'',
		   socialCreditCode:'',
		   legalRepresent:'',
		   registNum:'',
		   registFunds:'',
		   registCurrency:'',
		   foundDate:'',
		   businessValLower:'',
		   businessValUpper:'',
		   registStatus:'',
		   logoutDate:'',
		   revokeDate:'',
		   domicile:'',
		   registOrg:'',
		   type:'',
		   lastYearCheckYear:'',
		   lastYearCheckDate:'',
		   industryCategoryCode:'',
		   industryCategoryName:'',
		   nationEconomyIndustryCode:'',
		   nationEconomyIndustryName:'',
		   paidCapital:'',
		   originRegistNum:'',
		   approvalTime:''
		 },
		  reqForm:{
			page: 0, 
			size: 10,
			sort:'id,desc',
			id:''
		},
		reqLoading:true,
		reqId:'',
		reqIds:[],
	    addForm:{
		   cardCountry:'',
		   cardType:'',
		   cardNum:'',
		   cardEndDate:'',
		   cardStatus:'',
		   cardPublishCity:'',
		   isMainCard:''
		},
		addRules: {
				cardCountry: [
				  { required: true, message: '请输入证件国别', trigger: 'blur' }
				],
				cardType: [
				  { required: true, message: '请输入证件类型', trigger: 'blur' }
				],
				cardNum: [
				  { required: true, message: '请输入证件编号', trigger: 'blur' }
				],
				cardEndDate: [
				  { required: true, message: '请输入证件到期日期', trigger: 'blur' }
				],
				cardStatus: [
				  { required: true, message: '请输入证件状态', trigger: 'blur' }
				],
				cardPublishCity: [
				  { required: true, message: '请输入证件发布城市', trigger: 'blur' }
				],
		        isMainCard: [
				  { required: true, message: '请输入是否主证件', trigger: 'blur' }
				]

		},

		effectiveParams:{
		   id:'',
		   cardStatus:''
		},
      rules: {
        appID: [
          { required: true, message: '请输入appID', trigger: 'blur' }
        ],
        sysServiceProviderId: [
          { required: true, message: '请输入商家账号', trigger: 'blur' }
        ],
        privateKey: [
          { required: true, message: '商户私钥不能为空', trigger: 'blur' }
        ],
        publicKey: [
          { required: true, message: '支付宝公钥不能为空', trigger: 'blur' }
        ],
        returnUrl: [
          { required: true, message: '回调地址不能为空', trigger: 'blur' }
        ],
        notifyUrl: [
          { required: true, message: '回调地址不能为空', trigger: 'blur' }
        ]
      }
    }
  },
  created() {
	  console.log('id----',this.$route.params.id)
	  //this.id = this.$route.params.id
	  
	  console.log('id--------------',this.id)
	  	setTimeout(() => {
				 this.id = sessionStorage.getItem('comCustId')
				 this.reqForm.id = sessionStorage.getItem('comCustId')
				 console.log('this.id',this.id)
				 this.loading = true
				 let that = this
                 commerce(this.id).then(res => {
					   this.loading = false
					  // that.form = res
                      this.form = {
						    enterpriseName:res.enterpriseName,
							socialCreditCode:res.socialCreditCode,
							legalRepresent:res.legalRepresent,
							registNum:res.registNum,
							registFunds:res.registFunds,
							registCurrency:res.registCurrency,
							foundDate:res.foundDate,
							businessValLower:res.businessValLower,
							businessValUpper:res.businessValUpper,
							registStatus:res.registStatus,
							logoutDate:res.logoutDate,
							revokeDate:res.revokeDate,
							domicile:res.domicile,
							registOrg:res.registOrg,
							type:res.type,
							lastYearCheckYear:res.lastYearCheckYear,
							lastYearCheckDate:res.lastYearCheckDate,
							industryCategoryCode:res.industryCategoryCode,
							industryCategoryName:res.industryCategoryName,
							nationEconomyIndustryCode:res.nationEconomyIndustryCode,
							nationEconomyIndustryName:res.nationEconomyIndustryName,
							paidCapital:res.paidCapital,
							originRegistNum:res.originRegistNum,
							approvalTime:res.approvalTime
					  }
					   console.log('res',res)
                 }).catch(err => {
                       this.loading = false
                       console.log(err.response.data.message)
				}) 
         }, 500)
	  
  },
  methods: {
	   parseTime,
	   checkPermission,
	handleSelectionChange(val) {
		  console.log('val',val)
		   val.forEach((v) => {
               this.reqIds.push(v.id)
		   });
		   console.log('ids',this.reqIds)
		   this.reqId = this.reqIds.toString()
		   this.reqIds = []
	},
	add(){
		this.dialog = true;
	},
	cancelAdd(){
		this.resetForm()
	},
	resetForm() {
      this.dialog = false
	  this.$refs['forms'].resetFields()
	  this.addForm ={
		   cardCountry:'',
		   cardType:'',
		   cardNum:'',
		   cardEndDate:'',
		   cardStatus:'',
		   cardPublishCity:'',
		   isMainCard:''
	  }
	},
	addCredentials(){
		  this.$refs['forms'].validate((valid) => {
				if (valid) {
				this.addLoading = true
				addCredentials(this.addForm).then(res => {
					this.$notify({
					title: '新增成功',
					type: 'success',
					duration: 2500
					})
					this.credentials();
					this.addLoading = false
					this.dialog = false;
				}).catch(err => {
					this.addLoading = false
					console.log(err.response.data.message)
				})
				} else {
				return false
				}
			})
	},
	credentials(){
              credentials(this.reqForm).then(res => {
					this.total = res.totalElements
					this.data = res.content
					setTimeout(() => {
						this.reqLoading = false
					}, 170)
				}).catch(err => {
					this.reqLoading = false
					console.log(err.response.data.message)
				})
	},
	 effective(){
		 this.effectiveParams.id = this.reqId
		 this.effectiveParams.cardStatus = '1' 
		 if(this.effectiveParams.id == ''){
			this.$message.warning('请选择某个复选框') 
			return;
		 }
        effective(this.effectiveParams).then(res => {
            this.$notify({
              title: '已生效',
              type: 'success',
              duration: 2500
			})
			this.credentials();
            // this.loading = false
          }).catch(err => {
            // this.loading = false
            console.log(err.response.data.message)
          })
	 }, 

	 invalid(){
		 this.effectiveParams.id = this.reqId
		 this.effectiveParams.cardStatus = '0' 
		 if(this.effectiveParams.id == ''){
			this.$message.warning('请选择某个复选框') 
			return;
		 }
        effective(this.effectiveParams).then(res => {
            this.$notify({
              title: '已失效',
              type: 'success',
              duration: 2500
			})
			this.credentials();
            // this.loading = false
          }).catch(err => {
            // this.loading = false
            console.log(err.response.data.message)
          })
	 }, 

    doSubmit() {
      this.$refs['form'].validate((valid) => {
        if (valid) {
          this.loading = true
          update(this.form).then(res => {
            this.$notify({
              title: '修改成功',
              type: 'success',
              duration: 2500
            })
            this.loading = false
          }).catch(err => {
            this.loading = false
            console.log(err.response.data.message)
          })
        } else {
          return false
        }
      })
    }
  }
}
</script>

<style scoped> 
  .head_title{
    height:40px;line-height:40px;border-bottom: 2px solid #ce2731;color:#ce2731
  }
  .space{
	  margin-top:30px;
	  margin-bottom:10px
  }
   .one{
	   display:inline-block;
	   width:86.5%;
   }
   .two{
	   display:inline-block;
	   width:50%;
	
   }


</style>
